/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.actions;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;




public class ModificarPassForm extends org.apache.struts.action.ActionForm {

    private String pass1;

    private String pass2;


    public String getpass1() {
        return pass1;
    }

    public void setpass1(String pass1) {
        this.pass1 = formatear(pass1, 15);
    }

    public String getpass2() {
        return pass2;
    }

    public void setpass2(String pass2) {
        this.pass2 = formatear(pass2, 15);
    }

    public ModificarPassForm() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();

        if (getpass1() == null || getpass1().length() < 1 || getpass1().contains(" ")) {
            errors.add("pass1", new ActionMessage("error.Pass1.required"));
            // TODO: add 'error.name.required' key to your resources
        }

        if (! getpass2() .equals( getpass1())) {
            errors.add("pass2", new ActionMessage("error.Pass2.equal"));
            // TODO: add 'error.name.required' key to your resources
        }
        return errors;
    }
    public String formatear(String texto, int largo)
{
    texto=texto.replaceAll("Ã¡","á");
    texto=texto.replaceAll("Ã","Á");

    texto=texto.replaceAll("Ã©","é");
    texto=texto.replaceAll("Ã","É");

    texto=texto.replaceAll("Ã","Í");
    texto=texto.replaceAll("Ãº","ú");

    texto=texto.replaceAll("Ã","Ú");
    texto=texto.replaceAll("Ã±","ñ");

    texto=texto.replaceAll("Ã","Ñ");
    texto=texto.replaceAll("Ã³","ó");

    texto=texto.replaceAll("Ã","Ó");
    texto=texto.replaceAll("Ã","í");

    texto=texto.replaceAll("­Â­","");
    texto=texto.replaceAll("­","");

    if (texto.length()>largo) texto = texto.substring(0, largo);
    return texto;
}
}
